// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   DownLoadTxAction.java

package com.iphaeton.common.util;

import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.*;
import org.apache.struts.actions.DispatchAction;

public class DownLoadTxAction extends DispatchAction
{

    public DownLoadTxAction()
    {
    }

    public ActionForward download(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String name = (String)request.getAttribute("name");
        name = new String(name.getBytes("iso8859-1"), "GBK");
        String url = (String)request.getAttribute("url");
        response.setContentType("application/x-msdownload");
        response.setHeader("Content-disposition", "attachment; filename=" + new String(name.getBytes("GBK"), "iso8859-1"));
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        try
        {
            bis = new BufferedInputStream(new FileInputStream(url));
            bos = new BufferedOutputStream(response.getOutputStream());
            byte buff[] = new byte[2048];
            int bytesRead;
            while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) 
                bos.write(buff, 0, bytesRead);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        finally
        {
            if(bis != null)
                bis.close();
            if(bos != null)
                bos.close();
        }
        return null;
    }
}
